package 力扣日常刷题.木22一月.第10天0118;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/1/18
 * @description
 */
public class Demo23动态规划中等最小侧跳次数 {

    public int minSideJumps(int[] obstacles) {
        int n = obstacles.length;
        int[][] dp = new int[n+1][4];
        for (int i = 1; i <= n ; i++) {
            Arrays.fill(dp[i],Integer.MAX_VALUE);
        }
        dp[1][2] = 0;
        dp[1][1] = 1;
        dp[1][3] = 1;
        for (int i = 1; i < n; i++) {
            //设置成 无法从这个点到
            dp[i][obstacles[i]] = Integer.MAX_VALUE;
            for (int j = 1; j <= 3 ; j++) {
                if(obstacles[i] != j){
                    dp[i+1][j] = Math.min(dp[i][j],Math.min(Math.min(dp[i][1],dp[i][2]),dp[i][3])+1);
                }
            }
        }
        return Math.min(Math.min(dp[n][1],dp[n][2]),dp[n][3]);
    }
}
